package org.example.game.history;

import org.example.linkedlist.ListNode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/07/14 10:34
 */
public class Solution100368 {

    public static void main(String[] args) {
        ListNode head = new ListNode();
        head.val = 1;
        head.next = new ListNode(2, new ListNode(3, new ListNode(4, null)));
        ListNode rest = new Solution100368().modifiedList(new int[]{1}, head);

        while (rest != null){
            System.out.println(rest.val);
            rest = rest.next;
        }

    }

    public ListNode modifiedList(int[] nums, ListNode head) {
        ListNode res = new ListNode();

        HashMap<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            map.putIfAbsent(num, 0);
        }

        List<Integer> nodeValueList = new ArrayList<>();
        while (head != null){
            if(!map.containsKey(head.val)){
                nodeValueList.add(head.val);
            }
            head = head.next;
        }

        ListNode current = res;
        for (Integer value : nodeValueList) {
            current.next = new ListNode(value);
            current = current.next;
        }

        return res.next;
    }

}
